
const util = require('../../utils/util.js');
Page({
  data: {
    categoryId: '',
    name: '',
    tabs: [],
    topSwiperHeight:110,
    topimagesList: ['http://cdn.nbyingchuang.cn/miniapp-xjy-dev/public/haowu/haowutuijian.png', 'http://cdn.nbyingchuang.cn/miniapp-xjy-dev/public/haowu/haowutuijian3.png'],
    // list: [
    //   {
    //     name: '放养老母鸡此处是文案',
    //     url: 'http://115.238.142.66:8067/kaikai/images/fenlei/jujia.png',
    //     price: '120',
    //     id: 1
    //   },
    //   {
    //     name: '黑金棒纸尿裤/拉拉裤',
    //     url: 'http://115.238.142.66:8067/kaikai/images/fenlei/jujia.png',
    //     price: '97',
    //     id: 2
    //   },
    //   {
    //     name: '贝亲奶瓶 玻璃',
    //     url: 'http://115.238.142.66:8067/kaikai/images/fenlei/jujia.png',
    //     price: '120',
    //     id: 3
    //   },
    //   {
    //     name: '大号藤编收纳筐',
    //     url: 'http://115.238.142.66:8067/kaikai/images/fenlei/jujia.png',
    //     price: '120',
    //     id: 4
    //   },
    // ]
    list: []
  },
  getTopData() {
    util.https('categoriesMgmt/categoriesQry', {
      "pid": "2"
    }, (res) => {
      let resData = [{ name: '全部', id: '' }].concat(res.categoriesBoList)
      this.setData({
        tabs: resData
      })
    }, (res) => {
      wx.showModal({
        title: '温馨提示',
        content: res.errorMsg,
        confirmColor: '#F08302',
        showCancel: false,
        success(res) {
        }
      })

    })
  },
  getData() {
    return
    let data = this.data;
    util.https('goodsMgmt/goodsQry', {
      "categoryId": data.categoryId,
      "name": data.name === '全部' ? '' : data.name,
    }, (res) => {
      console.log(res)
      this.setData({
        list: res.goodsBoList
      })
    }, (res) => {
      wx.showModal({
        title: '温馨提示',
        content: res.errorMsg,
        confirmColor: '#F08302',
        showCancel: false,
        success(res) {
        }
      })

    })
  },
  onShow() {

    if (typeof this.getTabBar === 'function' &&
      this.getTabBar()) {
      this.getTabBar().setData({
        selected: 3
      })
    }
  },
  onLoad() {
    const systemInfo = wx.getSystemInfoSync();
    console.log(systemInfo)
    let height1 = (systemInfo.windowWidth - 375) * 0.4 + 110;
    this.setData({
      topSwiperHeight: height1,
    })
    this.getTopData();
    this.getData();
   
  },
  switchTab(e) {
    const data = e.currentTarget.dataset
    this.setData({
      categoryId: data.path
    });
    this.getData()
  },
  itemClick(e) {
    const data = e.currentTarget.dataset
    wx.setStorageSync('zhenxuan', data.item)
    console.log('itemClick')
    console.log(data)
    wx.setStorageSync('address_get', '');
    wx.setStorageSync('address_get_type', '');
    wx.navigateTo({ url: '/page4/detail/index?id=' + data.item.id })
  },
  doOrder() {
    wx.navigateGo({ url: '/page4/order/index' })
  },
  onShareAppMessage() {

  },
})
